package com.ranyk.www.util;

import com.ranyk.www.enums.WebSiteFileBelongEnum;

import java.io.File;

/**
 * CLASS_NAME: UserUtils.java <br/>
 *
 * @author ranyk           <br/>
 * @version V1.0           <br/>
 * @decription: 用户工具类  <br/>
 * @date: 2022-04-03 <br/>
 */
@SuppressWarnings("unused")
public class UserUtils {


    /**
     * 用户编号后缀位数
     */
    private static final int SUFFIX_NUMBER = 2;

    /**
     * 系统默认头像
     */
    private static final String[] DEFAULT_AVATAR = {"avatar_1.jpg", "avatar_2.jpg", "avatar_3.jpg", "avatar_4.jpg", "avatar_5.jpg", "avatar_6.jpg", "avatar_7.jpg", "avatar_8.jpg"};

    /**
     * 私有化构造方法
     */
    private UserUtils() {
        throw new AssertionError();
    }

    /**
     * 获得用户编号
     */
    public static Long getUserNumber() {
        String prefixNumber = Long.toString(System.currentTimeMillis());
        String suffixNumber = RandomUtils.number(SUFFIX_NUMBER);
        String userNumber = prefixNumber + suffixNumber;
        return Long.valueOf(userNumber);
    }

    /**
     * 获得系统默认的头像
     */
    public static String getPicImg() {
        // 系统默认头像名
        String picImg = RandomUtils.randomItem(DEFAULT_AVATAR);
        // 系统 默认头像路径
        String picImgUrl = WebSiteFileBelongEnum.DEFAULT.getBelong() +
                File.separator +
                WebSiteFileBelongEnum.AVATAR.getBelong() +
                File.separator +
                picImg;

        // 将绝对路径"\"替换成"/"
        return picImgUrl.replaceAll("\\\\", "/");
    }

}
